let fs = require('fs');
//异步函数没有返回值，都是通过callback回调函数来处理
    fs.open('./async3.txt','w',function(err,fd) {
    if(err) {
        console.log(err);
    } else {
        let msg = 'hello异步文件写入!';
        // fs.writeSync(fd,msg);
        // fs.closeSync(fd);   //文件open时传递的文件描述符
        bf = Buffer.from(msg);
        // fs.write(fd,bf,2,bf.length-2,function(err,writeNum,bf2){
        fs.write(fd,bf,function(err,writeNum,bf2){
            console.log(err);
            console.log(writeNum)
            //buffer 转字符串 bf.toString(); 
            console.log(bf2.toString());
            console.log('done!');
        });
        console.log('写入完成!');   
        //异步的文件关闭
        fs.close(fd,function (err) {
            console.log("已关闭");
            console.log(err);
        })
    }
})  
console.log('end'); //先输出